package concurrency2;

public class LockDemo {

    private static final Object LOCK = new Object();

    public static void main(String[] args) {
        Thread a = new Thread(() -> {
            synchronized (LOCK) {
                for (int i = 0; i < 20; i++) {
                    System.out.println(Thread.currentThread().getName() + ":" + i);
                }
            }
        }, "A");

        a.start();

        Thread b = new Thread(() -> {
            synchronized (LOCK) {
                for (int i = 0; i < 20; i++) {
                    System.out.println(Thread.currentThread().getName() + ":" + i);
                }
            }
        }, "B");

        b.start();
    }
}
